//index.js
//获取应用实例
var app = getApp()

Page({
  data: {
    swiperCurrent:1,
    toView: "",
    motto: 'MiHome_Store',
    userInfo: {},
    indicatorDots: true,
    indicatorDotsitem: false,
    autoplay: true,
    interval: 3000,
    duration: 100,
    multipleitem:3,
    circular:true,
    imgUrl: app.globalData.imgUrl,
    newgoods: [],
    hotgoods: [],
    butimg: [{"igurl":"https://img1.imgtn.bdimg.com/it/u=619035232,399014571&fm=27&gp=0.jpg"},
      { "igurl": "https://img1.imgtn.bdimg.com/it/u=619035232,399014571&fm=27&gp=0.jpg" },
      { "igurl": "https://img1.imgtn.bdimg.com/it/u=619035232,399014571&fm=27&gp=0.jpg" },
      { "igurl": "https://img1.imgtn.bdimg.com/it/u=619035232,399014571&fm=27&gp=0.jpg" },
      { "igurl": "https://img1.imgtn.bdimg.com/it/u=619035232,399014571&fm=27&gp=0.jpg" }],
    banner_list: []
  },
  onPullDownRefresh: function () {
    console.log('onPullDownRefresh')
  },
  scroll: function (e) {
    if (this.data.toView == "top") {
      this.setData({
        toView: ""
      })
    }
  },

  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  tap: function () {
    this.setData({
      toView: "top"
    })
  },
  swiperChange: function (swiper) {
    this.setData({
      swiperCurrent: swiper.detail.current   //获取当前轮播图片的下标
    })
  },
  onitem: function (e) {
    var that = this;
    var param = this.data.swiperCurrent + 1;
    console.log(e);
    wx.navigateTo({
      url: "../classtype/classtype?classify="+e.target.id
    })
    
  },
  onNew: function (e) {
    var that = this;
    var param = e.target.id;
    console.log(param);
    //网络请求 GET方法
    wx.request({
      url: `https://www.azhouaa.cn/wxs/User/getNew?nextid=${param}`,
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      //成功后的回调
      success: function (res) {
        console.log('返回成功:' + res),
          that.setData({
            images: res.data //成功后进入页面
          })

      }
    })
    wx.navigateTo({
      url: "../classtype/classtype?classify=" + e.target.id
    })
  }, 
  onHot: function (e) {
    var that = this;
    var param = e.target.id;
    console.log(param);
    //网络请求 GET方法
    wx.request({
      url: `https://www.azhouaa.cn/wxs/User/getHot?nextid=${param}`,
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      //成功后的回调
      success: function (res) {
        console.log('返回成功:' + res),
          that.setData({
            images: res.data //成功后进入页面
          })

      }
    })
    wx.navigateTo({
      url: "../classtype/classtype?classify=" + e.target.id
    })
  },
  onLoad: function () {//加载小程序得时候同时从服务器端获取图片
    var that = this;
    //网络请求 GET方法
    wx.request({
      url: "https://www.azhouaa.cn/wxs/User/getNew",
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      //成功后的回调
      success: function (res) {
        var da = res.data.msg;
        console.log('返回成功onload:' + da);
          that.setData({
            newgoods: da //成功后进入页面
          })
        
      }
    })

    wx.request({
      url: "https://www.azhouaa.cn/wxs/User/getHeader",
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      //成功后的回调
      success: function (res) {
        var da = res.data.msg;
        console.log('返回成功onload:' + da);
        that.setData({
          banner_list: da //成功后进入页面
        })

      }
    })

    wx.request({
      url: "https://www.azhouaa.cn/wxs/User/getHot",
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      //成功后的回调
      success: function (res) {
        var da = res.data.msg;
        console.log('返回成功onloadhot:' + da);
        that.setData({
          hotgoods: da //成功后进入页面
        })

      }
    })
    
  },
  
})
